<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="com.kh.pajx.sop.util.common.FormatDate"%>
<%
	String path = request.getContextPath();
String temp_str = FormatDate.getSendDate(new Date());
String max_date = FormatDate.getUseDate(new Date());
%>
<script type="text/javascript">
var appnum=0.0;
function allCheck(check) {//全选
   　var checkbox=document.getElementsByName("cost");
        if(check.checked){
				for(var i=0;i<checkbox.length;i++){
　						checkbox[i].checked="checked";
               }
				getAll();
		}else{
               for(var i=0;i<checkbox.length;i++){
　						checkbox[i].checked="";
				} 
               document.getElementById("appSumFee").value=0.0;
		}  
}
function allCheckChild(check) {//全选
   var appList=document.getElementsByName("appnum"+check.value);
   tem = document.getElementById("appSumFee").value*1;
   bb = document.getElementById("appSumFee");
   var num=0.0;
   for(var i=0;i<appList.length;i++){
		num +=appList[i].value*1;
      }
        if(check.checked){
				bb.value = tem+num;
		}else{
               bb.value = tem-num; 
		}  
}
  function getAll(){
	  var  merList={};
	  appnum=0.0;
	  var    tem = document.getElementById("appSumFee").value*1;
	  var  bb = document.getElementById("appSumFee");
	  var  appList= $("input[id='appnum']");
		appList.each(function(i) {
			if(this.value>0);
			appnum +=Number(this.value);
		})
		 bb.value=Math.round(appnum*10)/10;
  }
  $(document).ready(function(){
	  init();
  });
  function init(){
	  var tform = document.forms['form1'];
	  for (var i=0;i<tform.length;i++){
	     var e = tform.elements[i];
	     if (e.type == "checkbox")
	    	 if(e.disabled==false)
	      e.checked = true;
	  } 
	  document.getElementById("appSumFee").value="0";
	  getAll();
  }
 function save(){
	  var url="foreign_addBalanceApp.action";
	  var  appSumFee=$("#appSumFee").val();
	  var appDate=$("#appDate").val();
	  var merList ={};
	  merList = $("input[name='cost']:checked");
	  if(merList.length < 1){
			alertMsg.info("请先选择您要申请的记录!");
			return false;
		}
	  //if(appSumFee*1<1){
		//	alert("申请金额不能小于1元");
		//	return false;
	  //}
	alertMsg.confirm("确定要申请吗？", {
		okCall : function() {
	  var list = {};//定义一个数组
	  merList.each(function(i) {
			list[i]=$(this).val()+",";
		});
	  data={
			  "dataList":list,
			  "model.appSumFee":appSumFee,
			  "model.appDate":$.trim(appDate),
			  "model.appType":1,
			  "model.billState":1
	  }
	  $.ajax({ 
		  url: url, 
		  type:"post",
		  data :data,
		  dataType:"json",
		  success: function(message){
			  navTabAjaxDone(message);
	      }});
		}})
 }
</script>
<div class="pageHeader">
    <div class="searchBar">
		<table class="searchContent" >
			<tr>
				<td>
					申请人:
				</td>
				<td>
				${sessionScope.currentUser.userName }
				</td>
				<td>
					申请金额:
				</td>
				<td>
				<input type="text" id="appSumFee" name="appSumFee"
						value="0" readonly="readonly">
				</td>
				<td>
					申请时间:
				</td>
				<td>
				<input type="text" id="appDate" name="appDate" class="date" dateFmt="yyyy-MM-dd HH:mm:ss" readonly="true"  maxDate="<%=max_date%>"	value="<%=temp_str%>"/>
				</td>
			</tr>
		</table>
		</div>
		
</div>
		<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
				<li><a class="edit"
				href="javascript:void(0)" onclick="save()"><span>申请</span></a></li>
				<li class="line">line</li>

		</ul>
	</div>
			<form action="" name="form1" id="form1">
				<table class="table" width="100%" layoutH="120">
					<thead>
						<tr>
							<th><input type="checkbox" onclick="allCheck(this)"
								checked="checked" /></th>
							<th>学校名称</th>
							<th>结算日期</th>
							<th>总人数</th>
							<th>本期有效用户数</th>
							<th>上期有效用户数</th>
							<th>新增有效用户数</th>
							<th>开通率</th>
							<th>客户经理费用</th>
							<th>学校费用</th>
							<th>话费返还结算</th>
							<th>管理员费用</th>
						</tr>
					</thead>

					<tbody>
						<c:forEach items="${foreignList}" var="fb" varStatus="countStatus">
							<tr id="row${fb.uuid}">
								<td><input name="cost" onchange="" id="count"
									type="checkbox" value="${fb.uuid}" checked="checked"
									onclick="allCheckChild(this)" /></td>
								<td>${fb.hsSclName}</td>
								<td>${fb.ywEndDate}</td>
								<td>${fb.ywPopSumNum}</td>
								<td>${fb.ywBvuserNum}</td>
								<td>${fb.ywPastBvuserNum}</td>
								<td>${fb.ywBaddNum}</td>
								<td>${fb.ywBuseRate}</td>
								<td>${fb.ywCustomCost}<span
									style="margin-right: 5px;float: right;display: none"> <input
										id="appnum" name="appnum${fb.uuid}" type="text"
										value="${fb.ywCustomCost}" />
								</span>
								</td>
								<td>${fb.ywSchoolCost}<span
									style="margin-right: 5px;float: right;display: none"> <input
										value="${fb.ywSchoolCost}" id="appnum" name="appnum${fb.uuid}" />
								</span>
								</td>
								<td>${fb.ywPhoneCost}<span
									style="margin-right: 5px;float: right; display: none"> <input
										id="appnum" value="${fb.ywPhoneCost}" name="appnum${fb.uuid}" />
								</span>
								</td>
								<td>${fb.ywSysoperCost}<span style="display: none">
										<input id="appnum" value="${fb.ywSysoperCost}"
										name="appnum${fb.uuid}" />
								</span>
								</td>
							</tr>

						</c:forEach>
					</tbody>

				</table>
			</form>
</div>